import time, traceback
def schedule(actions, time_intervals=None, params=None, stopper=None, pauser=None):    
    if not time_intervals:
        time_intervals = [0 for x in actions]    
    if not params:
        params = [() for x in actions]
    time_stamps = [0 for x in actions]
    while 1:
        if stopper and stopper():            
            break
        if pauser and pauser():
            time.sleep(0.5) 
            continue  
        for i, action in enumerate(actions):
            if time.time() - time_stamps[i] > time_intervals[i]:
                try:
                    action(*params[i])
                except:
                    traceback.print_exc()
                time_stamps[i] = time.time() 
                #give other processes some cpu time
                time.sleep(0.0001)                           